home *** CD-ROM | disk | FTP | other *** search
- /* functions to show a chosen item from an index key file,etc.
- * 870805-13... ^z
- */
-
- #include <stdio.h> /* for FILE, getc(), etc. */
- #include <strings.h> /* for strncpy(), etc. */
- #include <ctype.h> /* for isprint(), etc. */
- #include <unix.h> /* for exit(), time(), etc. */
- #include <proto.h> /* for function prototypes */
- #include "brwsr.h" /* for various definitions */
- #include "brwsr.proto.h" /* for my function prototypes */
-
-
- /* function to show whatever the current item is, in whatever level
- * the user is at the moment.... basically, it just routes the
- * request to whichever is the appropriate agent to take care of
- * it, for INDEX, CONTEXT, or TEXT levels....
- */
-
- void show_current_item ()
- {
- extern int level;
- extern FILE *doc_file;
-
- if (doc_file == NULL)
- {
- beep ();
- printf ("No file open!\n");
- return;
- }
-
- if (level == INDEX)
- show_current_index_item ();
- else if (level == CONTEXT)
- show_current_context_item ();
- else
- show_current_text_item ();
- }
-
-
- /* function to show the current INDEX item (count of occurrences followed
- * by the indexed word itself) ... send copy to notes file, if open....
- */
-
- void show_current_index_item ()
- {
- extern KEY_REC this_rec, prev_rec;
- extern long current_item[], subset_rec_count;
- extern FILE *notes_file;
- extern char *subset;
- long count_subset_recs ();
- void get_key_rec ();
-
- get_key_rec (&prev_rec, current_item[INDEX] - 1);
- get_key_rec (&this_rec, current_item[INDEX]);
-
- if (subset == NULL)
- {
- printf ("%6ld %.28s\n", this_rec.ccount - prev_rec.ccount,
- this_rec.kkey);
- if (notes_file != NULL)
- fprintf (notes_file, "%6ld %.28s\n",
- this_rec.ccount - prev_rec.ccount, this_rec.kkey);
- }
- else
- {
- subset_rec_count = count_subset_recs (&this_rec, &prev_rec);
- printf ("%6ld/%-6ld %.28s\n", subset_rec_count,
- this_rec.ccount - prev_rec.ccount, this_rec.kkey);
- if (notes_file != NULL)
- fprintf (notes_file, "%6ld/%-6ld %.28s\n", subset_rec_count,
- this_rec.ccount - prev_rec.ccount, this_rec.kkey);
- }
- }
-
-
- /* function to show the current CONTEXT item, a line in the form of a
- * key-word-in-context (KWIC) display with the indexed term in the'
- * middle ... the line is filtered so that the presence of tabs, <cr>'s,
- * or other nasty control characters won't cause any problems...
- * a little testing is needed to take care of end-effects, so that
- * nothing happens for context lines near either end of the document
- * file ... finally, send a copy to the notes file, if open....
- */
-
- void show_current_context_item ()
- {
- register int n, m;
- register long p;
- char buf[CONTEXT_LINE_LENGTH + 1];
- extern long current_item[];
- extern FILE *doc_file;
-
- p = current_item[TEXT] - CONTEXT_OFFSET;
- n = 0;
- if (p < 0)
- {
- for ( ; n < -p; ++n)
- buf[n] = ' ';
- p = 0;
- }
- if (fseek (doc_file, p, 0) != 0)
- {
- beep ();
- printf ("Error in fseek() getting a context line to show!\n");
- return;
- }
- if ((m = fread (buf + n, sizeof (char), CONTEXT_LINE_LENGTH - n,
- doc_file)) == 0)
- {
- beep ();
- printf ("Error in fread() getting a context line to show!\n");
- return;
- }
- n += m;
- for ( ; n < CONTEXT_LINE_LENGTH; ++n)
- buf[n] = ' ';
- for (n = 0; n < CONTEXT_LINE_LENGTH; ++n)
- if (! isprint (buf[n] & 0xFF))
- buf[n] = ' ';
- buf[CONTEXT_LINE_LENGTH] = '\0';
- printf ("%s\n", buf);
- if (notes_file != NULL)
- fprintf (notes_file, "%s\n", buf);
- }
-
-
- /* function to show the current TEXT item, a line from the document file
- * itself ... copy to notes file also, if so desired....
- */
-
- void show_current_text_item ()
- {
- char buf[STRLEN + 1];
- extern long current_item[];
- extern FILE *doc_file;
-
- if (fseek (doc_file, current_item[TEXT], 0) != 0)
- {
- beep ();
- printf ("Error in fseek() getting a text line to show!\n");
- return;
- }
- if (fgets (buf, STRLEN, doc_file) == NULL)
- {
- beep ();
- printf ("Error in fgets() getting a text line to show!\n");
- return;
- }
- printf ("%s", buf);
- if (notes_file != NULL)
- fprintf (notes_file, "%s", buf);
- }
-
-
-